package com.project.Dao.impl;

import com.project.Bean.UserBean;
import com.project.Dao.IUserDao;
import java.sql.SQLException;
/**
 * @Title: IUserDao
 * @Package: com.project.Dao
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/6/21 - 5:44
 */
@SuppressWarnings("all")

public class UserDaoImpl extends BaseDao implements IUserDao {
    @Override
    public UserBean getUserByNameAndPwd(String name, String pwd) {
        UserBean user = null;
        this.getConnection();
        try {
            ps = con.prepareStatement("select * from t_user where u_username=? and u_password=?");
            ps.setObject(1,name);
            ps.setObject(2,pwd);
            rs = ps.executeQuery();
            if (rs.next()){
                user = new UserBean();
                user.setId(rs.getInt("pk_id"));
                user.setUsername(rs.getString("u_username"));
                user.setPassword(rs.getString("u_password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }

    @Override
    public void add(UserBean user) {
        this.getConnection();
        try {
            ps = con.prepareStatement("insert into t_user (e_username,e_userpassword) values ('蔡七','777');");
            ps.setObject(1,user.getUsername());
            ps.setObject(2,user.getPassword());
            rs = ps.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            closeConnection();
        }
    }
}
